<template lang="">
  <div>
    <el-row>
      <el-col :span="3"> </el-col>
      <el-col :span="4" style="text-align: center"> </el-col>
      <el-col :span="4" style="text-align:center;">
        <el-select
          filterable
          v-model="ser.product_id"
          placeholder="请选择产品"
          style="width: 100%"
        >
          <el-option
            v-for="(item, index) in productList"
            :key="index"
            :label="item.product_name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-col>
      <el-col :span="6"  style="text-align:center;">
        <el-date-picker
          v-model="order_data"
          @change="order_data_change"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-col>
      <el-col :span="8">
        <el-button
          @click="company_name_click(0)"
          icon="el-icon-search"
          class="add_btn"
        >
          搜索</el-button
        >
        <el-button
          icon="el-icon-refresh"
          @click="company_name_clicks"
          class="add_btn"
        >
          重置</el-button
        >
        <el-button @click="search(2)" class="add_btn"> 打印</el-button>
      </el-col>
    </el-row>

    <el-table :data="dataList" stripe style="width: 100%" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection"> </el-table-column>
      <el-table-column prop="id" label="ID" width="60"> </el-table-column>
      <el-table-column prop="warehouse_entry_time" label="入库日期" width="100">
      </el-table-column>
      <el-table-column label="客户名称" width="80">
        <template slot-scope="scope">
          {{
            scope.row.order.customer
              ? scope.row.order.customer.customer_name
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="订单号" width="120">
        <template slot-scope="scope">
          {{ scope.row.order.order_number }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="流水号" width="70">
        <template slot-scope="scope">
          {{ scope.row.order.serial_number }}
        </template>
      </el-table-column> -->

      <el-table-column label="产品名称" width="120">
        <template slot-scope="scope">
          {{ scope.row.order.product_name.product_name }}
        </template>
      </el-table-column>
      <el-table-column label="产品型号" width="120">
        <template slot-scope="scope">
          {{ scope.row.order.model_number_name.model_number }}
        </template>
      </el-table-column>
      <el-table-column label="方向" width="120">
        <template slot-scope="scope">
          {{ scope.row.direction }}
        </template>
      </el-table-column>
      <el-table-column label="规格" width="120">
        <template slot-scope="scope">
          {{
            scope.row.order.specification
              ? scope.row.order.specification.specification
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="颜色" width="70">
        <template slot-scope="scope">
          {{ scope.row.order.color ? scope.row.order.color.color : "" }}
        </template>
      </el-table-column>
      <el-table-column label="备注" width="150">
        <template slot-scope="scope">
          {{ scope.row.order.remark }}
        </template>
      </el-table-column>
      <el-table-column label="盘点状态" width="120">
        <template slot-scope="scope">
          <span
            v-if="scope.row.is_check == 2"
            style="color: #333; font-weight: bold"
            >未盘点</span
          >
          <span
            v-if="scope.row.is_check == 1"
            style="color: green; font-weight: bold"
            >已盘点</span
          >
        </template>
      </el-table-column>
      <el-table-column prop="logistics_status" label="发货状态" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.logistics_status == 1" style="color: #dd8211"
            >待发货</span
          >
          <span v-if="scope.row.logistics_status == 2" style="color: #f1420d"
            >未发货</span
          >
          <span v-if="scope.row.logistics_status == 4" style="color: #b47425"
            >部分待发货</span
          >
          <span v-if="scope.row.logistics_status == 5" style="color: #b47425"
            >部分未发货</span
          >
          <span v-if="scope.row.logistics_status == 3" style="color: #0ca747"
            >已发货</span
          >
        </template>
      </el-table-column>
      <el-table-column label="件数" prop="num" width="70"> </el-table-column>
      <el-table-column label="仓库" width="120">
        <template slot-scope="scope">
          {{ scope.row.warehouse?scope.row.warehouse.warehouse_name:'' }}
        </template>
      </el-table-column>
      <el-table-column label="货架" width="120">
        <template slot-scope="scope">
          {{scope.row.goods_shelf?scope.row.goods_shelf.goods_shelf_name:'' }}
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        @prev-click="prev"
        @next-click="next"
        :current-page.sync="pagination.page"
        :page-size="pagination.per_page"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { getCheckLogList ,  getProductList,downloadcode,batchSettingYifahuo} from "@/api/product/index";
export default {
  data() {
    return {
        order_data:'',
      ser: {
        product_id:'',
        start_time:'',
        end_time:''
      },
      pagination: {
        per_page: 10,
        page: 1,
      },
      total: 0,
      productList: [],
      dataList: [],
    };
  },
  mounted() {
    this.get_CheckLogList();
    this.getproduct()
  },
  methods: {
    handleSelectionChange(val){
        let ids=[]
        val.forEach(item=>{
            ids.push(item.order_id)
        })
        batchSettingYifahuo(ids).then(res=>{
            if(res.code==200){
                this.$message.success("操作成功");
            }
        })
    },
    search(type) {
      if (type == 0) {
        this.pagination.per_page = 10;
        this.pagination.page = 1;
      }
      getCheckLogList({ ...this.ser, ...this.pagination }).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
          if (type == 2) {
            if (res.data.data.length > 0) {
              this.$message.success("正在导出订单列表");
              this.exports_w();
            }
          }
        }
      });
    },
    // 导出
    exports_w() {
      let data = {
        ...this.ser,
        export: 1,
      };
      downloadcode(data).then((res) => {
        //创建一个隐藏的a连接，
        const link = document.createElement("a");
        let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
        link.style.display = "none";
        //设置连接
        link.href = URL.createObjectURL(blob);
        link.download = "成品库";
        document.body.appendChild(link);
        //模拟点击事件
        link.click();
      });
    },
    order_data_change(val) {
      this.ser.start_time = val[0];
      this.ser.end_time = val[1];
    },
     //产品列表
     getproduct() {
      getProductList().then((res) => {
        if (res.code == 200) {
          this.productList = res.data.data;
        }
      });
    },
    get_CheckLogList() {
      getCheckLogList().then((res) => {
        this.dataList = res.data.data;
        this.total = res.data.total;
      });
    },
    company_name_click(type) {
      if (type == 0) {
        this.pagination.per_page = 10;
        this.pagination.page = 1;
      }
      getCheckLogList({ ...this.ser, ...this.pagination }).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
        }
      });
    },
    company_name_clicks() {
      this.ser = {
        product_id:'',
        start_time:'',
        end_time:''
      };
      this.pagination={
        per_page: 10,
        page: 1,
      }
      getCheckLogList(this.pagination).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
        }
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pagination.page = val;
      this.get_CheckLogList();
    },
    prev() {
      this.pagination.page = this.pagination.page - 1;
      this.get_CheckLogList();
    },
    next() {
      this.pagination.page = this.pagination.page + 1;
      this.get_CheckLogList();
    },
  },
};
</script>
<style lang=""></style>
